﻿using System;
using System.Collections;
using System.ComponentModel.Composition;
using System.Linq;
using Cubicle.Core.Interfaces;
using Cubicle.Core.Processors;

namespace Cubicle.Excel.Processors
{
    [Export("Cubicle.Excel.Processors.MarshalList", typeof(IProcessor<object>))]
    [ExportMetadata("Name", "MarshalList")]
    [ExportMetadata("Description", "Convert IList into Object[]")]
    public class MarshalList : ConditionalProcessor<object>
    {

        public override bool Condition(object request)
        {
            return !(request is Array) && (request is IList);
        }

        public override object ConditionalProcess(object request)
        {
            var lst = (IList) request;
            return lst.Cast<object>().ToArray();
        }

    }
}